function [LatestRst,msg] = run(this,userMode,replaceLastSuiteFlg,saveResultFile,varargin)
% class: TestRunner
% [LatestRst,msg] = run(this,userMode,replaceLastSuiteFlg,saveResultFile,userTestSuiteName)
% replaceLastSuiteFlg > 0 :delete Last Suite and create a new one
% replaceLastSuiteFlg = 0 :create a new one
% replaceLastSuiteFlg < 0 :use the suite of user specified name or last suite
try
    try
        mustBeTextScalar(userMode)
        mustBeNumericOrLogical(replaceLastSuiteFlg)
        mustBeNumericOrLogical(saveResultFile)
        % add session path
        addSessionPath(this)
        % create test file and return the newly created test suite to run
        if nargin > 4
            userTestSuiteName = varargin{1};
            mustBeTextScalar(userTestSuiteName)
            [msg,testSuiteObj] = this.createTestFile(userMode,replaceLastSuiteFlg,userTestSuiteName);
        else
            [msg,testSuiteObj] = this.createTestFile(userMode,replaceLastSuiteFlg);
        end
        if ~isempty(testSuiteObj)
            resultObj = run(testSuiteObj);
        else
            LatestRst = [];
            return
        end
        switch userMode
            case 'MIL'
                this.MILResultObj = resultObj;
            case 'SIL'
                this.SILResultObj = resultObj;
            case 'PIL'
                this.PILResultObj = resultObj;
            otherwise

        end
        if saveResultFile
            this.exportResultFile(userMode,testSuiteObj.Name);
        end
        
        % define rpt file path
        defineRptFilePath(this,userMode);

        % clean previous coverage report and coverage data then create new
        % coverage cvt file and coverage report
        this.cleanOldRun(resultObj,userMode);
        
        LatestRst.nPassed = resultObj.NumPassed;
        LatestRst.nFailed = resultObj.NumFailed;
        LatestRst.nDisabled= resultObj.NumDisabled;
        LatestRst.nIncomplete = resultObj.NumIncomplete;
        
    catch ex
        rethrowTraceableMessage(ex,'See below');
    end
catch ex
    msg = ex.message;
    LatestRst = [];
end
end